DepthToSpace ================= 将输入张量的深度通道按 ``block_size`` 重排到空间维(Depth → Space)。 输入/输出均为 **NHWC** 格式:``[batch, height, width, channel]``。 要求输入通道数 :math:`C` 能被 :math:`B^{2}` 整除,其中 :math:`B` 为 ``block_size``。 设输入形状为 :math:`[N, H, W, C]`,则输出形状为: .. math:: \begin{aligned} N_{out} &= N \\ H_{out} &= H \cdot B \\ W_{out} &= W \cdot B \\ C_{out} &= C / B^{2} \end{aligned} **mode 约定** - ``mode = 0``:DCR(Depth-Column-Row) - ``mode != 0``:CRD(Column-Row-Depth) 当前测试与常用路径为 DCR。对输入坐标 :math:`(n, y, x, c)`,在 DCR 模式下: .. math:: \begin{aligned} y_{out} &= y \cdot B + \left\lfloor (c / C_{out}) / B \right\rfloor \\ x_{out} &= x \cdot B + (c / C_{out}) \bmod B \\ c_{out} &= c \bmod C_{out} \end{aligned} 即 :math:`O[n, y_{out}, x_{out}, c_{out}] = I[n, y, x, c]`。 输入: - **input** - 输入数据地址 - **in_shape** - 输入形状,格式为 ``[batch, height, width, channel]`` - **block_size** - 分块因子 :math:`B` - **mode** - 重排模式(0 为 DCR,非 0 为 CRD) - **core_mask** - 核掩码(仅共享存储版本使用) 输出: - **output** - 输出数据地址 支持平台: ``FT78NE`` ``MT7004`` .. note:: - FT78NE 支持 int8, int16, int32, fp32, fp64, cplx64, cplx128 - MT7004 支持 int16, int32, fp16, fp32, cplx64 **共享存储版本:** .. c:function:: void i8_depth_to_space_s(int8_t *input, int8_t *output, int *in_shape, int block_size, int mode, int core_mask) .. c:function:: void i16_depth_to_space_s(int16_t *input, int16_t *output, int *in_shape, int block_size, int mode, int core_mask) .. c:function:: void i32_depth_to_space_s(int *input, int *output, int *in_shape, int block_size, int mode, int core_mask) .. c:function:: void hp_depth_to_space_s(float16 *input, float16 *output, int *in_shape, int block_size, int mode, int core_mask) .. c:function:: void fp_depth_to_space_s(float *input, float *output, int *in_shape, int block_size, int mode, int core_mask) .. c:function:: void dp_depth_to_space_s(double *input, double *output, int *in_shape, int block_size, int mode, int core_mask) .. c:function:: void c64_depth_to_space_s(float *input, float *output, int *in_shape, int block_size, int mode, int core_mask) .. c:function:: void c128_depth_to_space_s(double *input, double *output, int *in_shape, int block_size, int mode, int core_mask) **C调用示例:** .. code-block:: c :linenos: :emphasize-lines: 12 // MT7004 示例(共享存储多核,DDR 地址) void TestDepthToSpaceSMCFp32(int core_mask) { int core_id = get_core_id(); int logic_core_id = GetLogicCoreId(core_mask, core_id); int core_num = GetCoreNum(core_mask); float *input = (float *)0x81000000; float *output = (float *)0x82000000; int in_shape[4] = {1, 8, 8, 4}; int block_size = 2; int mode = 0; // DCR sys_bar(0, core_num); fp_depth_to_space_s(input, output, in_shape, block_size, mode, core_mask); } void main() { int core_mask = 0b1111; TestDepthToSpaceSMCFp32(core_mask); } **私有存储版本:** .. c:function:: void i8_depth_to_space_p(int8_t *input, int8_t *output, int *in_shape, int block_size, int mode) .. c:function:: void i16_depth_to_space_p(int16_t *input, int16_t *output, int *in_shape, int block_size, int mode) .. c:function:: void i32_depth_to_space_p(int *input, int *output, int *in_shape, int block_size, int mode) .. c:function:: void hp_depth_to_space_p(float16 *input, float16 *output, int *in_shape, int block_size, int mode) .. c:function:: void fp_depth_to_space_p(float *input, float *output, int *in_shape, int block_size, int mode) .. c:function:: void dp_depth_to_space_p(double *input, double *output, int *in_shape, int block_size, int mode) .. c:function:: void c64_depth_to_space_p(float *input, float *output, int *in_shape, int block_size, int mode) .. c:function:: void c128_depth_to_space_p(double *input, double *output, int *in_shape, int block_size, int mode) **C调用示例:** .. code-block:: c :linenos: :emphasize-lines: 8 // MT7004 示例(私有存储单核,AM 地址) void TestDepthToSpaceAMFp32(void) { float *input = (float *)0x10000000; float *output = (float *)0x10010000; int in_shape[4] = {1, 8, 8, 4}; int block_size = 2; int mode = 0; // DCR fp_depth_to_space_p(input, output, in_shape, block_size, mode); } void main() { TestDepthToSpaceAMFp32(); }